package com.topgay.service;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.topgay.dao.MemberDAO;
import com.topgay.domain.Member;

@Service
public class MemberServiceImpl implements MemberService{
	
	@Autowired
	private MemberDAO dao;
	
	//ID로 회원 조회
	@Override
	public Member getMemberById(String id) throws SQLException {
		return dao.selectMemberById(id);
	}
	
	// 닉네임으로 회원 조회
	@Override
	public Member getMemberByNickname(String nickname) throws SQLException {
		return dao.selectMemberByNickname(nickname);
	}
	@Override
	public int updateLoginCheck(String id) throws SQLException {
		return dao.updateLoginCheck(id);
	};
	public int updateLogoutCheck(String id) throws SQLException{
		return dao.updateLogoutCheck(id);
	}

	// 가입처리 메소드
	@Override
	public void joinMember(Member member) throws SQLException{

		// 2. 디비에 회원정보 등록 처리
		dao.insertMember(member);
	}

	//회원 정보 수정
	@Override
	public void modifyMember(Member member) throws SQLException{
		dao.updateMember(member);
	}
	//회원 삭제
	@Override
	public void removeMemberById(String id) throws SQLException {
		dao.deleteMemberById(id);
	}
	//아이디 찾기

	public Member findMemberById(String name, String hp)throws SQLException{
		return dao.findMemberById(name, hp);
	}
	//패스워드 찾기
	public Member findMemberByPw(String id, String name, String hp)throws SQLException{
		return dao.findMemberByPw(id, name, hp);
	}	
	
	@Override
	public List<Member> getMemberList(int page, String role){
		
//		1. DAO메소드를 이용해 매개변수로 받은 페이지에 보여줄 게시물들을 ArrayList로 조회
		return dao.selectMemberList(page, role);
		
	}
	
	@Override
	public int getTotalContent(String role){
//		2-1 : DAO의 메소드를 이용해 전체 게시물 수 조회
		return dao.selectTotalContent(role);
	}

	@Override
	public Member getMemberContentByNo(String id) {
		return dao.selectMemberContentById(id);
	}
	
}
